package org.store.math;

import java.util.BitSet;

public class Math {

    public static double factorial(double n) {
        if (n <= 1) {
            return 1;
        } else {
            return factorial(n - 1) * n;
        }
    }

    public static double sum(double n) {
        double res = 0.0;

        if (n < 0) {
            throw new IllegalArgumentException("n can't be less than 0");
        }
        if (n == 0.0) {
            return 0;
        } else {
            res = sum(n - 1) + n;
        }
        return res;
    }

    public static int fibonacci(int n) {
        if (n < 0) {
            throw new IllegalArgumentException("Can't be less than 0");
        }
        return fibonacci(n, new int[n]);
    }

    private static int fibonacci(int n, int[] arr) {
        if (n == 0) return 0;
        else if (n <= 2) return 1;

        int i = arr[n - 1];
        int j = arr[n - 2];

        if (i == 0) {
            i = fibonacci(n - 1, arr);
            arr[n - 1] = i;
        }

        if (j == 0) {
            j = fibonacci(n - 2, arr);
            arr[n - 2] = j;
        }
        return i + j;
    }

    public static int pow(int x, int y) {

        if (y == 0) {
            return 1;
        }

        if (y == 1) {
            return x;
        } else {
            return pow(x, y - 1) * x;
        }
    }


    public static void main(String[] args) throws InterruptedException {
        BitSet bitSet = new BitSet();
        for (int i = 0; i < 100000000; i++) {
            bitSet.set(i);
        }
        Thread.sleep(Integer.MAX_VALUE);
    }
}
